﻿using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using Arch.Common.IoC;
using Microsoft.Practices.Unity;
using System.ServiceModel.Dispatcher;

namespace Arch.Client.Services
{
    public class NotifyProxyOperationBehavior : IOperationBehavior
    {
        [Dependency]
        public IDependencyContainer Container { get; set; }

        void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
        {
            IClientMessageFormatter currentFormatter = proxy.Formatter;
            //TODO : Make a better injection here :
            var proxyFormatter = new ClientNotifyProxyFormatter(currentFormatter);
            Container.BuildUp(proxyFormatter);
            proxy.Formatter = proxyFormatter;
        }

        public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
        }

        public void Validate(OperationDescription operationDescription)
        {
        }
    }
}